package com.haochu.xxl.model;

import com.haochu.xxl.util.Constants;

/**
 * @author Administrator 每一个元素的封装对象
 */
public class PointItem {
    // x坐标
    private int x;
    // y坐标
    private int y;
    // 元素类型 0-正常元素图片 | 1-爆炸动画图片 | 2-金边特效 | 3-上下点头特效 | 4-左右摇头特效
    private int type;
    // 元素下标
    private int index;
    // 是否消除
    private boolean remove = false;
    // 上下点头动画图片下标
    private int animIndexUD;
    // 左右摇头动画图片下标
    private int animIndexLR;
    // 是否处于特效动画中
    private boolean animating = false;


    public PointItem() {

    }

    public PointItem(int x, int y, int index) {
        this.x = x;
        this.y = y;
        this.index = index;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        PointItem p = (PointItem) o;
        return this.x == p.getX() && this.y == p.getY() && indexEq(p);
    }

    /**
     * 横向相邻且颜色相等
     */
    public boolean nextEqX(PointItem p) {
        return nextX(p) && indexEq(p);
    }

    /**
     * 纵向相邻且颜色相等
     */
    public boolean nextEqY(PointItem p) {
        return nextY(p) && indexEq(p);
    }

    /**
     * 仅仅横向相邻
     */
    public boolean nextX(PointItem p) {
        return Math.abs(this.x - p.getX()) == Constants.SIZE && this.y == p.getY();
    }

    /**
     * 仅仅纵向相邻
     */
    public boolean nextY(PointItem p) {
        return this.x == p.getX() && Math.abs(this.y - p.getY()) == Constants.SIZE;
    }

    /**
     * 仅仅位置相等
     */
    public boolean positionEq(PointItem p) {
        return this.x == p.getX() && this.y == p.getY();
    }

    public boolean indexEq(PointItem p) {
        return this.index == p.getIndex();
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public boolean isRemove() {
        return remove;
    }

    public boolean isNotRemove() {
        return !isRemove();
    }

    public void setRemove(boolean remove) {
        this.remove = remove;
    }

    public int getAnimIndexUD() {
        return animIndexUD;
    }

    public void setAnimIndexUD(int animIndexUD) {
        this.animIndexUD = animIndexUD;
    }

    public int getAnimIndexLR() {
        return animIndexLR;
    }

    public void setAnimIndexLR(int animIndexLR) {
        this.animIndexLR = animIndexLR;
    }

    public boolean isAnimating() {
        return animating;
    }

    public void setAnimating(boolean animating) {
        this.animating = animating;
    }
}
